{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 11.1 Introducing the Timestamp object"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 11.1.1 How Python works with datetimes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import datetime as dt\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.date(1991, 4, 12)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "birthday = dt.date(1991, 4, 12)\n",
    "birthday = dt.date(year = 1991, month = 4, day = 12)\n",
    "birthday"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1991"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "birthday.year"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "birthday.month"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "12"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "birthday.day"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**NOTE**: I've commented out the code below so that the Notebook can run without raising an error."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "# birthday.month = 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.time(6, 43, 25)"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "alarm_clock = dt.time(6, 43, 25)\n",
    "alarm_clock = dt.time(hour = 6, minute = 43, second = 25)\n",
    "alarm_clock"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.time(0, 0)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt.time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.time(9, 0, 42)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt.time(hour = 9, second = 42)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.time(19, 43, 22)"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt.time(hour = 19, minute = 43, second = 22)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alarm_clock.hour"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "43"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alarm_clock.minute"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "alarm_clock.second"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(1969, 7, 20, 22, 56, 20)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "moon_landing = dt.datetime(1969, 7, 20, 22, 56, 20)\n",
    "moon_landing = dt.datetime(\n",
    "    year = 1969,\n",
    "    month = 7,\n",
    "    day = 20,\n",
    "    hour = 22,\n",
    "    minute = 56,\n",
    "    second = 20\n",
    ")\n",
    "moon_landing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2020, 1, 1, 0, 0)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt.datetime(2020, 1, 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.timedelta(days=62, seconds=14292)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dt.timedelta(\n",
    "    weeks = 8,\n",
    "    days = 6,\n",
    "    hours = 3, \n",
    "    minutes = 58,\n",
    "    seconds = 12\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 11.1.2 How `pandas` works with datetimes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('1991-04-12 00:00:00')"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "pd.Timestamp(1991, 4, 12)\n",
    "pd.Timestamp(year = 1991, month = 4, day = 12)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(pd.Timestamp(year = 1991, month = 4, day = 12) \n",
    " == dt.date(year = 1991, month = 4, day = 12))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(pd.Timestamp(year = 1991, month = 4, day = 12, minute = 2)\n",
    " == dt.datetime(year = 1991, month = 4, day = 12, minute = 2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(pd.Timestamp(year = 1991, month = 4, day = 12, minute = 2) \n",
    " == dt.datetime(year = 1991, month = 4, day = 12, minute = 1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2015-03-31 00:00:00')"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Timestamp(\"2015-03-31\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2015-03-31 00:00:00')"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Timestamp(\"2015/03/31\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2015-03-31 00:00:00')"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Timestamp(\"03/31/2015\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2021-03-08 08:35:15')"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Timestamp(\"2021-03-08 08:35:15\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2021-03-08 18:13:29')"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Timestamp(\"2021-03-08 6:13:29 PM\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timestamp('2000-02-03 21:35:22')"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Timestamp(dt.datetime(2000, 2, 3, 21, 35, 22))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2000\n",
      "2\n",
      "3\n",
      "21\n",
      "35\n",
      "22\n"
     ]
    }
   ],
   "source": [
    "my_time = pd.Timestamp(dt.datetime(2000, 2, 3, 21, 35, 22))\n",
    "print(my_time.year) \n",
    "print(my_time.month)\n",
    "print(my_time.day)\n",
    "print(my_time.hour) \n",
    "print(my_time.minute)\n",
    "print(my_time.second)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 11.2 Storing Multiple Timestamps in a DatetimeIndex"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=3, step=1)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series([1, 2, 3]).index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['A', 'B', 'C'], dtype='object')"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Series([1, 2, 3], index = [\"A\", \"B\", \"C\"]).index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2020-01-01', '2020-02-01', '2020-03-01'], dtype='datetime64[ns]', freq=None)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "timestamps = [\n",
    "    pd.Timestamp(\"2020-01-01\"),\n",
    "    pd.Timestamp(\"2020-02-01\"),\n",
    "    pd.Timestamp(\"2020-03-01\"),\n",
    "]\n",
    "\n",
    "pd.Series([1, 2, 3], index = timestamps).index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2020-01-01', '2020-02-01', '2020-03-01'], dtype='datetime64[ns]', freq=None)"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetimes = [\n",
    "    dt.datetime(2020, 1, 1),\n",
    "    dt.datetime(2020, 2, 1),\n",
    "    dt.datetime(2020, 3, 1),\n",
    "]\n",
    "\n",
    "pd.Series([1, 2, 3], index = datetimes).index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2018-01-02', '2016-04-12', '2009-09-07'], dtype='datetime64[ns]', freq=None)"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string_dates = [\"2018/01/02\", \"2016/04/12\", \"2009/09/07\"]\n",
    "pd.DatetimeIndex(string_dates)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2018-01-02', '2016-04-12', '2009-09-07'], dtype='datetime64[ns]', freq=None)"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mixed_dates = [\n",
    "    dt.date(2018, 1, 2),\n",
    "    \"2016/04/12\",\n",
    "    pd.Timestamp(2009, 9, 7)\n",
    "]\n",
    "\n",
    "dt_index = pd.DatetimeIndex(mixed_dates)\n",
    "dt_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2018-01-02    100\n",
       "2016-04-12    200\n",
       "2009-09-07    300\n",
       "dtype: int64"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pd.Series(data = [100, 200, 300], index = dt_index)\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2009-09-07    300\n",
       "2016-04-12    200\n",
       "2018-01-02    100\n",
       "dtype: int64"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s.sort_index()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "morning = pd.Timestamp(\"2020-01-01 11:23:22 AM\")\n",
    "evening = pd.Timestamp(\"2020-01-01 11:23:22 PM\")\n",
    "\n",
    "morning < evening"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 11.3\tConverting Column or Index Values to Datetimes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1962-01-02</td>\n",
       "      <td>0.096026</td>\n",
       "      <td>0.092908</td>\n",
       "      <td>0.092908</td>\n",
       "      <td>0.092908</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1962-01-03</td>\n",
       "      <td>0.094467</td>\n",
       "      <td>0.092908</td>\n",
       "      <td>0.092908</td>\n",
       "      <td>0.094155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1962-01-04</td>\n",
       "      <td>0.094467</td>\n",
       "      <td>0.093532</td>\n",
       "      <td>0.094155</td>\n",
       "      <td>0.094155</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1962-01-05</td>\n",
       "      <td>0.094779</td>\n",
       "      <td>0.093844</td>\n",
       "      <td>0.094155</td>\n",
       "      <td>0.094467</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1962-01-08</td>\n",
       "      <td>0.095714</td>\n",
       "      <td>0.092285</td>\n",
       "      <td>0.094467</td>\n",
       "      <td>0.094155</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         Date      High       Low      Open     Close\n",
       "0  1962-01-02  0.096026  0.092908  0.092908  0.092908\n",
       "1  1962-01-03  0.094467  0.092908  0.092908  0.094155\n",
       "2  1962-01-04  0.094467  0.093532  0.094155  0.094155\n",
       "3  1962-01-05  0.094779  0.093844  0.094155  0.094467\n",
       "4  1962-01-08  0.095714  0.092285  0.094467  0.094155"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney = pd.read_csv(\"disney.csv\")\n",
    "disney.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Date      object\n",
       "High     float64\n",
       "Low      float64\n",
       "Open     float64\n",
       "Close    float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [],
   "source": [
    "disney = pd.read_csv(\"disney.csv\", parse_dates = [\"Date\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatetimeIndex(['2015-01-01', '2016-02-02', '2017-03-03'], dtype='datetime64[ns]', freq=None)"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "string_dates = [\"2015-01-01\", \"2016-02-02\", \"2017-03-03\"]\n",
    "dt_index = pd.to_datetime(string_dates)\n",
    "dt_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   1962-01-02\n",
       "1   1962-01-03\n",
       "2   1962-01-04\n",
       "3   1962-01-05\n",
       "4   1962-01-08\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.to_datetime(disney[\"Date\"]).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [],
   "source": [
    "disney[\"Date\"] = pd.to_datetime(disney[\"Date\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Date     datetime64[ns]\n",
       "High            float64\n",
       "Low             float64\n",
       "Open            float64\n",
       "Close           float64\n",
       "dtype: object"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney.dtypes"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 11.4 Using the DatetimeProperties Object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<pandas.core.indexes.accessors.DatetimeProperties object at 0x7fbf8e4dca90>"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[\"Date\"].dt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   1962-01-02\n",
       "1   1962-01-03\n",
       "2   1962-01-04\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[\"Date\"].head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    2\n",
       "1    3\n",
       "2    4\n",
       "Name: Date, dtype: int64"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[\"Date\"].dt.day.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    1\n",
       "2    1\n",
       "Name: Date, dtype: int64"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[\"Date\"].dt.month.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1962\n",
       "1    1962\n",
       "2    1962\n",
       "Name: Date, dtype: int64"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[\"Date\"].dt.year.head(3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1\n",
       "1    2\n",
       "2    3\n",
       "3    4\n",
       "4    0\n",
       "Name: Date, dtype: int64"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[\"Date\"].dt.dayofweek.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0      Tuesday\n",
       "1    Wednesday\n",
       "2     Thursday\n",
       "3       Friday\n",
       "4       Monday\n",
       "Name: Date, dtype: object"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[\"Date\"].dt.day_name().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "disney[\"Day of Week\"] = disney[\"Date\"].dt.day_name()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [],
   "source": [
    "group = disney.groupby(\"Day of Week\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Day of Week</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Friday</th>\n",
       "      <td>23.767304</td>\n",
       "      <td>23.318898</td>\n",
       "      <td>23.552872</td>\n",
       "      <td>23.554498</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Monday</th>\n",
       "      <td>23.377271</td>\n",
       "      <td>22.930606</td>\n",
       "      <td>23.161392</td>\n",
       "      <td>23.162543</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Thursday</th>\n",
       "      <td>23.770234</td>\n",
       "      <td>23.288687</td>\n",
       "      <td>23.534561</td>\n",
       "      <td>23.540359</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Tuesday</th>\n",
       "      <td>23.791234</td>\n",
       "      <td>23.335267</td>\n",
       "      <td>23.571755</td>\n",
       "      <td>23.562907</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Wednesday</th>\n",
       "      <td>23.842743</td>\n",
       "      <td>23.355419</td>\n",
       "      <td>23.605618</td>\n",
       "      <td>23.609873</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  High        Low       Open      Close\n",
       "Day of Week                                            \n",
       "Friday       23.767304  23.318898  23.552872  23.554498\n",
       "Monday       23.377271  22.930606  23.161392  23.162543\n",
       "Thursday     23.770234  23.288687  23.534561  23.540359\n",
       "Tuesday      23.791234  23.335267  23.571755  23.562907\n",
       "Wednesday    23.842743  23.355419  23.605618  23.609873"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "group.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    January\n",
       "1    January\n",
       "2    January\n",
       "3    January\n",
       "4    January\n",
       "Name: Date, dtype: object"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[\"Date\"].dt.month_name().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14722    False\n",
       "14723    False\n",
       "14724    False\n",
       "14725     True\n",
       "14726    False\n",
       "Name: Date, dtype: bool"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[\"Date\"].dt.is_quarter_start.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Day of Week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>1962-10-01</td>\n",
       "      <td>0.064849</td>\n",
       "      <td>0.062355</td>\n",
       "      <td>0.063913</td>\n",
       "      <td>0.062355</td>\n",
       "      <td>Monday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>314</th>\n",
       "      <td>1963-04-01</td>\n",
       "      <td>0.087989</td>\n",
       "      <td>0.086704</td>\n",
       "      <td>0.087025</td>\n",
       "      <td>0.086704</td>\n",
       "      <td>Monday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>377</th>\n",
       "      <td>1963-07-01</td>\n",
       "      <td>0.096338</td>\n",
       "      <td>0.095053</td>\n",
       "      <td>0.096338</td>\n",
       "      <td>0.095696</td>\n",
       "      <td>Monday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>441</th>\n",
       "      <td>1963-10-01</td>\n",
       "      <td>0.110467</td>\n",
       "      <td>0.107898</td>\n",
       "      <td>0.107898</td>\n",
       "      <td>0.110467</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>565</th>\n",
       "      <td>1964-04-01</td>\n",
       "      <td>0.116248</td>\n",
       "      <td>0.112394</td>\n",
       "      <td>0.112394</td>\n",
       "      <td>0.116248</td>\n",
       "      <td>Wednesday</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Date      High       Low      Open     Close Day of Week\n",
       "189 1962-10-01  0.064849  0.062355  0.063913  0.062355      Monday\n",
       "314 1963-04-01  0.087989  0.086704  0.087025  0.086704      Monday\n",
       "377 1963-07-01  0.096338  0.095053  0.096338  0.095696      Monday\n",
       "441 1963-10-01  0.110467  0.107898  0.107898  0.110467     Tuesday\n",
       "565 1964-04-01  0.116248  0.112394  0.112394  0.116248   Wednesday"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[disney[\"Date\"].dt.is_quarter_start].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Day of Week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>251</th>\n",
       "      <td>1962-12-31</td>\n",
       "      <td>0.074501</td>\n",
       "      <td>0.071290</td>\n",
       "      <td>0.074501</td>\n",
       "      <td>0.072253</td>\n",
       "      <td>Monday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>440</th>\n",
       "      <td>1963-09-30</td>\n",
       "      <td>0.109825</td>\n",
       "      <td>0.105972</td>\n",
       "      <td>0.108541</td>\n",
       "      <td>0.107577</td>\n",
       "      <td>Monday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>502</th>\n",
       "      <td>1963-12-31</td>\n",
       "      <td>0.101476</td>\n",
       "      <td>0.096980</td>\n",
       "      <td>0.097622</td>\n",
       "      <td>0.101476</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>564</th>\n",
       "      <td>1964-03-31</td>\n",
       "      <td>0.115605</td>\n",
       "      <td>0.112394</td>\n",
       "      <td>0.114963</td>\n",
       "      <td>0.112394</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>628</th>\n",
       "      <td>1964-06-30</td>\n",
       "      <td>0.101476</td>\n",
       "      <td>0.100191</td>\n",
       "      <td>0.101476</td>\n",
       "      <td>0.100834</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Date      High       Low      Open     Close Day of Week\n",
       "251 1962-12-31  0.074501  0.071290  0.074501  0.072253      Monday\n",
       "440 1963-09-30  0.109825  0.105972  0.108541  0.107577      Monday\n",
       "502 1963-12-31  0.101476  0.096980  0.097622  0.101476     Tuesday\n",
       "564 1964-03-31  0.115605  0.112394  0.114963  0.112394     Tuesday\n",
       "628 1964-06-30  0.101476  0.100191  0.101476  0.100834     Tuesday"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[disney[\"Date\"].dt.is_quarter_end].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Day of Week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>1962-02-01</td>\n",
       "      <td>0.096338</td>\n",
       "      <td>0.093532</td>\n",
       "      <td>0.093532</td>\n",
       "      <td>0.094779</td>\n",
       "      <td>Thursday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>41</th>\n",
       "      <td>1962-03-01</td>\n",
       "      <td>0.095714</td>\n",
       "      <td>0.093532</td>\n",
       "      <td>0.093532</td>\n",
       "      <td>0.095714</td>\n",
       "      <td>Thursday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>83</th>\n",
       "      <td>1962-05-01</td>\n",
       "      <td>0.087296</td>\n",
       "      <td>0.085426</td>\n",
       "      <td>0.085738</td>\n",
       "      <td>0.086673</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>105</th>\n",
       "      <td>1962-06-01</td>\n",
       "      <td>0.079814</td>\n",
       "      <td>0.077943</td>\n",
       "      <td>0.079814</td>\n",
       "      <td>0.079814</td>\n",
       "      <td>Friday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>147</th>\n",
       "      <td>1962-08-01</td>\n",
       "      <td>0.068590</td>\n",
       "      <td>0.068278</td>\n",
       "      <td>0.068590</td>\n",
       "      <td>0.068590</td>\n",
       "      <td>Wednesday</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Date      High       Low      Open     Close Day of Week\n",
       "22  1962-02-01  0.096338  0.093532  0.093532  0.094779    Thursday\n",
       "41  1962-03-01  0.095714  0.093532  0.093532  0.095714    Thursday\n",
       "83  1962-05-01  0.087296  0.085426  0.085738  0.086673     Tuesday\n",
       "105 1962-06-01  0.079814  0.077943  0.079814  0.079814      Friday\n",
       "147 1962-08-01  0.068590  0.068278  0.068590  0.068590   Wednesday"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[disney[\"Date\"].dt.is_month_start].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Day of Week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>1962-01-31</td>\n",
       "      <td>0.093844</td>\n",
       "      <td>0.092908</td>\n",
       "      <td>0.093532</td>\n",
       "      <td>0.093532</td>\n",
       "      <td>Wednesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>40</th>\n",
       "      <td>1962-02-28</td>\n",
       "      <td>0.094779</td>\n",
       "      <td>0.093220</td>\n",
       "      <td>0.094155</td>\n",
       "      <td>0.093220</td>\n",
       "      <td>Wednesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>82</th>\n",
       "      <td>1962-04-30</td>\n",
       "      <td>0.087608</td>\n",
       "      <td>0.085738</td>\n",
       "      <td>0.087608</td>\n",
       "      <td>0.085738</td>\n",
       "      <td>Monday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>1962-05-31</td>\n",
       "      <td>0.082308</td>\n",
       "      <td>0.079814</td>\n",
       "      <td>0.079814</td>\n",
       "      <td>0.079814</td>\n",
       "      <td>Thursday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>146</th>\n",
       "      <td>1962-07-31</td>\n",
       "      <td>0.069214</td>\n",
       "      <td>0.068278</td>\n",
       "      <td>0.068278</td>\n",
       "      <td>0.068590</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Date      High       Low      Open     Close Day of Week\n",
       "21  1962-01-31  0.093844  0.092908  0.093532  0.093532   Wednesday\n",
       "40  1962-02-28  0.094779  0.093220  0.094155  0.093220   Wednesday\n",
       "82  1962-04-30  0.087608  0.085738  0.087608  0.085738      Monday\n",
       "104 1962-05-31  0.082308  0.079814  0.079814  0.079814    Thursday\n",
       "146 1962-07-31  0.069214  0.068278  0.068278  0.068590     Tuesday"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[disney[\"Date\"].dt.is_month_end].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Day of Week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "Empty DataFrame\n",
       "Columns: [Date, High, Low, Open, Close, Day of Week]\n",
       "Index: []"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[disney[\"Date\"].dt.is_year_start].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Open</th>\n",
       "      <th>Close</th>\n",
       "      <th>Day of Week</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>251</th>\n",
       "      <td>1962-12-31</td>\n",
       "      <td>0.074501</td>\n",
       "      <td>0.071290</td>\n",
       "      <td>0.074501</td>\n",
       "      <td>0.072253</td>\n",
       "      <td>Monday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>502</th>\n",
       "      <td>1963-12-31</td>\n",
       "      <td>0.101476</td>\n",
       "      <td>0.096980</td>\n",
       "      <td>0.097622</td>\n",
       "      <td>0.101476</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>755</th>\n",
       "      <td>1964-12-31</td>\n",
       "      <td>0.117853</td>\n",
       "      <td>0.116890</td>\n",
       "      <td>0.116890</td>\n",
       "      <td>0.116890</td>\n",
       "      <td>Thursday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1007</th>\n",
       "      <td>1965-12-31</td>\n",
       "      <td>0.154141</td>\n",
       "      <td>0.150929</td>\n",
       "      <td>0.153498</td>\n",
       "      <td>0.152214</td>\n",
       "      <td>Friday</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1736</th>\n",
       "      <td>1968-12-31</td>\n",
       "      <td>0.439301</td>\n",
       "      <td>0.431594</td>\n",
       "      <td>0.434163</td>\n",
       "      <td>0.436732</td>\n",
       "      <td>Tuesday</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           Date      High       Low      Open     Close Day of Week\n",
       "251  1962-12-31  0.074501  0.071290  0.074501  0.072253      Monday\n",
       "502  1963-12-31  0.101476  0.096980  0.097622  0.101476     Tuesday\n",
       "755  1964-12-31  0.117853  0.116890  0.116890  0.116890    Thursday\n",
       "1007 1965-12-31  0.154141  0.150929  0.153498  0.152214      Friday\n",
       "1736 1968-12-31  0.439301  0.431594  0.434163  0.436732     Tuesday"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[disney[\"Date\"].dt.is_year_end].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 11.5 Adding and Subtracting Durations of Time"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<DateOffset: days=5, months=4, years=3>"
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.DateOffset(years = 3, months = 4, days = 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   1962-01-02\n",
       "1   1962-01-03\n",
       "2   1962-01-04\n",
       "3   1962-01-05\n",
       "4   1962-01-08\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[\"Date\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   1962-01-07\n",
       "1   1962-01-08\n",
       "2   1962-01-09\n",
       "3   1962-01-10\n",
       "4   1962-01-13\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(disney[\"Date\"] + pd.DateOffset(days = 5)).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   1961-12-30\n",
       "1   1961-12-31\n",
       "2   1962-01-01\n",
       "3   1962-01-02\n",
       "4   1962-01-05\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(disney[\"Date\"] - pd.DateOffset(days = 3)).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   1962-01-12 06:00:00\n",
       "1   1962-01-13 06:00:00\n",
       "2   1962-01-14 06:00:00\n",
       "3   1962-01-15 06:00:00\n",
       "4   1962-01-18 06:00:00\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(disney[\"Date\"] + pd.DateOffset(days = 10, hours = 6)).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   1960-09-21 17:57:00\n",
       "1   1960-09-22 17:57:00\n",
       "2   1960-09-23 17:57:00\n",
       "3   1960-09-24 17:57:00\n",
       "4   1960-09-27 17:57:00\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(\n",
    "    disney[\"Date\"]\n",
    "    - pd.DateOffset(\n",
    "        years = 1, months = 3, days = 10, hours = 6, minutes = 3\n",
    "    )\n",
    ").head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 11.6 Date Offsets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14722   2020-06-26\n",
       "14723   2020-06-29\n",
       "14724   2020-06-30\n",
       "14725   2020-07-01\n",
       "14726   2020-07-02\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "disney[\"Date\"].tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14722   2020-06-30\n",
       "14723   2020-06-30\n",
       "14724   2020-07-31\n",
       "14725   2020-07-31\n",
       "14726   2020-07-31\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(disney[\"Date\"] + pd.offsets.MonthEnd()).tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14722   2020-05-31\n",
       "14723   2020-05-31\n",
       "14724   2020-05-31\n",
       "14725   2020-06-30\n",
       "14726   2020-06-30\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(disney[\"Date\"] - pd.offsets.MonthEnd()).tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14722   2020-07-01\n",
       "14723   2020-07-01\n",
       "14724   2020-07-01\n",
       "14725   2020-08-01\n",
       "14726   2020-08-01\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(disney[\"Date\"] + pd.offsets.MonthBegin()).tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "14722   2020-06-01\n",
       "14723   2020-06-01\n",
       "14724   2020-06-01\n",
       "14725   2020-06-01\n",
       "14726   2020-07-01\n",
       "Name: Date, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(disney[\"Date\"] - pd.offsets.MonthBegin()).tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   2020-05-28\n",
       "1   2020-05-29\n",
       "2   2020-05-30\n",
       "dtype: datetime64[ns]"
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "may_dates = [\"2020-05-28\", \"2020-05-29\", \"2020-05-30\"]\n",
    "end_of_may = pd.Series(pd.to_datetime(may_dates))\n",
    "end_of_may"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   2020-05-31\n",
       "1   2020-05-31\n",
       "2   2020-05-31\n",
       "dtype: datetime64[ns]"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "end_of_may + pd.offsets.MonthEnd()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   2020-05-29\n",
       "1   2020-06-30\n",
       "2   2020-06-30\n",
       "dtype: datetime64[ns]"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "end_of_may + pd.offsets.BMonthEnd()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 11.7 The `timedelta` Object"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timedelta('8 days 07:06:05')"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "duration = pd.Timedelta(\n",
    "    days = 8,\n",
    "    hours = 7,\n",
    "    minutes = 6,\n",
    "    seconds = 5\n",
    ")\n",
    "\n",
    "duration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timedelta('0 days 03:05:12')"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.to_timedelta(\"3 hours, 5 minutes, 12 seconds\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timedelta('0 days 05:00:00')"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.to_timedelta(5, unit = \"hour\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "TimedeltaIndex(['5 days', '10 days', '15 days'], dtype='timedelta64[ns]', freq=None)"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.to_timedelta([5, 10, 15], unit = \"day\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timedelta('257 days 00:00:00')"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.Timestamp(\"1999-02-05\") - pd.Timestamp(\"1998-05-24\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_date</th>\n",
       "      <th>delivery_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5/24/98</td>\n",
       "      <td>2/5/99</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>4/22/92</td>\n",
       "      <td>3/6/98</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2/10/91</td>\n",
       "      <td>8/26/92</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>7/21/92</td>\n",
       "      <td>11/20/97</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>9/2/93</td>\n",
       "      <td>6/10/98</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  order_date delivery_date\n",
       "0    5/24/98        2/5/99\n",
       "1    4/22/92        3/6/98\n",
       "2    2/10/91       8/26/92\n",
       "3    7/21/92      11/20/97\n",
       "4     9/2/93       6/10/98"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deliveries = pd.read_csv(\"deliveries.csv\")\n",
    "deliveries.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [],
   "source": [
    "deliveries[\"order_date\"] = pd.to_datetime(\n",
    "    deliveries[\"order_date\"]\n",
    ")\n",
    "\n",
    "deliveries[\"delivery_date\"] = pd.to_datetime(\n",
    "    deliveries[\"delivery_date\"]\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [],
   "source": [
    "for column in [\"order_date\", \"delivery_date\"]:\n",
    "    deliveries[column] = pd.to_datetime(deliveries[column])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_date</th>\n",
       "      <th>delivery_date</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1998-05-24</td>\n",
       "      <td>1999-02-05</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1992-04-22</td>\n",
       "      <td>1998-03-06</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1991-02-10</td>\n",
       "      <td>1992-08-26</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1992-07-21</td>\n",
       "      <td>1997-11-20</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1993-09-02</td>\n",
       "      <td>1998-06-10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  order_date delivery_date\n",
       "0 1998-05-24    1999-02-05\n",
       "1 1992-04-22    1998-03-06\n",
       "2 1991-02-10    1992-08-26\n",
       "3 1992-07-21    1997-11-20\n",
       "4 1993-09-02    1998-06-10"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deliveries.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    257 days\n",
       "1   2144 days\n",
       "2    563 days\n",
       "3   1948 days\n",
       "4   1742 days\n",
       "dtype: timedelta64[ns]"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(deliveries[\"delivery_date\"] - deliveries[\"order_date\"]).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_date</th>\n",
       "      <th>delivery_date</th>\n",
       "      <th>duration</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1998-05-24</td>\n",
       "      <td>1999-02-05</td>\n",
       "      <td>257 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1992-04-22</td>\n",
       "      <td>1998-03-06</td>\n",
       "      <td>2144 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1991-02-10</td>\n",
       "      <td>1992-08-26</td>\n",
       "      <td>563 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1992-07-21</td>\n",
       "      <td>1997-11-20</td>\n",
       "      <td>1948 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1993-09-02</td>\n",
       "      <td>1998-06-10</td>\n",
       "      <td>1742 days</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  order_date delivery_date  duration\n",
       "0 1998-05-24    1999-02-05  257 days\n",
       "1 1992-04-22    1998-03-06 2144 days\n",
       "2 1991-02-10    1992-08-26  563 days\n",
       "3 1992-07-21    1997-11-20 1948 days\n",
       "4 1993-09-02    1998-06-10 1742 days"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deliveries[\"duration\"] = (\n",
    "    deliveries[\"delivery_date\"] - deliveries[\"order_date\"]\n",
    ")\n",
    "deliveries.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "order_date        datetime64[ns]\n",
       "delivery_date     datetime64[ns]\n",
       "duration         timedelta64[ns]\n",
       "dtype: object"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deliveries.dtypes"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   1998-05-24\n",
       "1   1992-04-22\n",
       "2   1991-02-10\n",
       "3   1992-07-21\n",
       "4   1993-09-02\n",
       "dtype: datetime64[ns]"
      ]
     },
     "execution_count": 88,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(deliveries[\"delivery_date\"] - deliveries[\"duration\"]).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0   1999-10-20\n",
       "1   2004-01-18\n",
       "2   1994-03-12\n",
       "3   2003-03-22\n",
       "4   2003-03-18\n",
       "dtype: datetime64[ns]"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(deliveries[\"delivery_date\"] + deliveries[\"duration\"]).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_date</th>\n",
       "      <th>delivery_date</th>\n",
       "      <th>duration</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>454</th>\n",
       "      <td>1990-05-24</td>\n",
       "      <td>1990-06-01</td>\n",
       "      <td>8 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>294</th>\n",
       "      <td>1994-08-11</td>\n",
       "      <td>1994-08-20</td>\n",
       "      <td>9 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1998-05-10</td>\n",
       "      <td>1998-05-19</td>\n",
       "      <td>9 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>499</th>\n",
       "      <td>1993-06-03</td>\n",
       "      <td>1993-06-13</td>\n",
       "      <td>10 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>143</th>\n",
       "      <td>1997-09-20</td>\n",
       "      <td>1997-10-06</td>\n",
       "      <td>16 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>152</th>\n",
       "      <td>1990-09-18</td>\n",
       "      <td>1999-12-19</td>\n",
       "      <td>3379 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>1990-04-02</td>\n",
       "      <td>1999-08-16</td>\n",
       "      <td>3423 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>458</th>\n",
       "      <td>1990-02-13</td>\n",
       "      <td>1999-11-15</td>\n",
       "      <td>3562 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>145</th>\n",
       "      <td>1990-03-07</td>\n",
       "      <td>1999-12-25</td>\n",
       "      <td>3580 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>448</th>\n",
       "      <td>1990-01-20</td>\n",
       "      <td>1999-11-12</td>\n",
       "      <td>3583 days</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>501 rows × 3 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "    order_date delivery_date  duration\n",
       "454 1990-05-24    1990-06-01    8 days\n",
       "294 1994-08-11    1994-08-20    9 days\n",
       "10  1998-05-10    1998-05-19    9 days\n",
       "499 1993-06-03    1993-06-13   10 days\n",
       "143 1997-09-20    1997-10-06   16 days\n",
       "..         ...           ...       ...\n",
       "152 1990-09-18    1999-12-19 3379 days\n",
       "62  1990-04-02    1999-08-16 3423 days\n",
       "458 1990-02-13    1999-11-15 3562 days\n",
       "145 1990-03-07    1999-12-25 3580 days\n",
       "448 1990-01-20    1999-11-12 3583 days\n",
       "\n",
       "[501 rows x 3 columns]"
      ]
     },
     "execution_count": 90,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deliveries.sort_values(\"duration\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timedelta('3583 days 00:00:00')"
      ]
     },
     "execution_count": 91,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deliveries[\"duration\"].max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timedelta('8 days 00:00:00')"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deliveries[\"duration\"].min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 93,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timedelta('1217 days 22:53:53.532934128')"
      ]
     },
     "execution_count": 93,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deliveries[\"duration\"].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 94,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    False\n",
       "1     True\n",
       "2     True\n",
       "3     True\n",
       "4     True\n",
       "Name: duration, dtype: bool"
      ]
     },
     "execution_count": 94,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# The two lines below are equivalent\n",
    "(deliveries[\"duration\"] > pd.Timedelta(days = 365)).head() \n",
    "(deliveries[\"duration\"] > \"365 days\").head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 95,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_date</th>\n",
       "      <th>delivery_date</th>\n",
       "      <th>duration</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1992-04-22</td>\n",
       "      <td>1998-03-06</td>\n",
       "      <td>2144 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1991-02-10</td>\n",
       "      <td>1992-08-26</td>\n",
       "      <td>563 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1992-07-21</td>\n",
       "      <td>1997-11-20</td>\n",
       "      <td>1948 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1993-09-02</td>\n",
       "      <td>1998-06-10</td>\n",
       "      <td>1742 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>1990-01-25</td>\n",
       "      <td>1994-10-02</td>\n",
       "      <td>1711 days</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  order_date delivery_date  duration\n",
       "1 1992-04-22    1998-03-06 2144 days\n",
       "2 1991-02-10    1992-08-26  563 days\n",
       "3 1992-07-21    1997-11-20 1948 days\n",
       "4 1993-09-02    1998-06-10 1742 days\n",
       "6 1990-01-25    1994-10-02 1711 days"
      ]
     },
     "execution_count": 95,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deliveries[deliveries[\"duration\"] > \"365 days\"].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 96,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>order_date</th>\n",
       "      <th>delivery_date</th>\n",
       "      <th>duration</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1992-04-22</td>\n",
       "      <td>1998-03-06</td>\n",
       "      <td>2144 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>1992-02-23</td>\n",
       "      <td>1998-12-30</td>\n",
       "      <td>2502 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>1992-10-17</td>\n",
       "      <td>1998-10-06</td>\n",
       "      <td>2180 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>1992-05-30</td>\n",
       "      <td>1999-08-15</td>\n",
       "      <td>2633 days</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>1990-01-20</td>\n",
       "      <td>1998-07-24</td>\n",
       "      <td>3107 days</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   order_date delivery_date  duration\n",
       "1  1992-04-22    1998-03-06 2144 days\n",
       "7  1992-02-23    1998-12-30 2502 days\n",
       "11 1992-10-17    1998-10-06 2180 days\n",
       "12 1992-05-30    1999-08-15 2633 days\n",
       "15 1990-01-20    1998-07-24 3107 days"
      ]
     },
     "execution_count": 96,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "long_time = (\n",
    "    deliveries[\"duration\"] > \"2000 days, 8 hours, 4 minutes\"\n",
    ")\n",
    "\n",
    "deliveries[long_time].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 11.8 Coding Challenge"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 11.8.1 Problems"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 97,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>stop_time</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2020-06-01 00:00:03.3720</td>\n",
       "      <td>2020-06-01 00:17:46.2080</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2020-06-01 00:00:03.5530</td>\n",
       "      <td>2020-06-01 01:03:33.9360</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2020-06-01 00:00:09.6140</td>\n",
       "      <td>2020-06-01 00:17:06.8330</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2020-06-01 00:00:12.1780</td>\n",
       "      <td>2020-06-01 00:03:58.8640</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2020-06-01 00:00:21.2550</td>\n",
       "      <td>2020-06-01 00:24:18.9650</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 start_time                 stop_time\n",
       "0  2020-06-01 00:00:03.3720  2020-06-01 00:17:46.2080\n",
       "1  2020-06-01 00:00:03.5530  2020-06-01 01:03:33.9360\n",
       "2  2020-06-01 00:00:09.6140  2020-06-01 00:17:06.8330\n",
       "3  2020-06-01 00:00:12.1780  2020-06-01 00:03:58.8640\n",
       "4  2020-06-01 00:00:21.2550  2020-06-01 00:24:18.9650"
      ]
     },
     "execution_count": 97,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "citi_bike = pd.read_csv(\"citibike.csv\")\n",
    "citi_bike.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 98,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1882273 entries, 0 to 1882272\n",
      "Data columns (total 2 columns):\n",
      " #   Column      Dtype \n",
      "---  ------      ----- \n",
      " 0   start_time  object\n",
      " 1   stop_time   object\n",
      "dtypes: object(2)\n",
      "memory usage: 28.7+ MB\n"
     ]
    }
   ],
   "source": [
    "citi_bike.info()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 11.8.2. Solutions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 99,
   "metadata": {},
   "outputs": [],
   "source": [
    "for column in [\"start_time\", \"stop_time\"]:\n",
    "    citi_bike[column] = pd.to_datetime(citi_bike[column])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 100,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.frame.DataFrame'>\n",
      "RangeIndex: 1882273 entries, 0 to 1882272\n",
      "Data columns (total 2 columns):\n",
      " #   Column      Dtype         \n",
      "---  ------      -----         \n",
      " 0   start_time  datetime64[ns]\n",
      " 1   stop_time   datetime64[ns]\n",
      "dtypes: datetime64[ns](2)\n",
      "memory usage: 28.7 MB\n"
     ]
    }
   ],
   "source": [
    "citi_bike.info()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 101,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    Monday\n",
       "1    Monday\n",
       "2    Monday\n",
       "3    Monday\n",
       "4    Monday\n",
       "Name: start_time, dtype: object"
      ]
     },
     "execution_count": 101,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "citi_bike[\"start_time\"].dt.day_name().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 102,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Tuesday      305833\n",
       "Sunday       301482\n",
       "Monday       292690\n",
       "Saturday     285966\n",
       "Friday       258479\n",
       "Wednesday    222647\n",
       "Thursday     215176\n",
       "Name: start_time, dtype: int64"
      ]
     },
     "execution_count": 102,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "citi_bike[\"start_time\"].dt.day_name().value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 103,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    0\n",
       "1    0\n",
       "2    0\n",
       "3    0\n",
       "4    0\n",
       "Name: start_time, dtype: int64"
      ]
     },
     "execution_count": 103,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "citi_bike[\"start_time\"].dt.dayofweek.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 104,
   "metadata": {},
   "outputs": [],
   "source": [
    "days_away_from_monday = citi_bike[\"start_time\"].dt.dayofweek"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 105,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0         2020-06-01 00:00:03.372\n",
       "1         2020-06-01 00:00:03.553\n",
       "2         2020-06-01 00:00:09.614\n",
       "3         2020-06-01 00:00:12.178\n",
       "4         2020-06-01 00:00:21.255\n",
       "                    ...          \n",
       "1882268   2020-06-29 23:59:41.116\n",
       "1882269   2020-06-29 23:59:46.426\n",
       "1882270   2020-06-29 23:59:47.477\n",
       "1882271   2020-06-29 23:59:53.395\n",
       "1882272   2020-06-29 23:59:53.901\n",
       "Name: start_time, Length: 1882273, dtype: datetime64[ns]"
      ]
     },
     "execution_count": 105,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "citi_bike[\"start_time\"] - pd.to_timedelta(\n",
    "    days_away_from_monday, unit = \"day\"\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 106,
   "metadata": {},
   "outputs": [],
   "source": [
    "dates_rounded_to_monday = citi_bike[\n",
    "    \"start_time\"\n",
    "] - pd.to_timedelta(days_away_from_monday, unit = \"day\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 107,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2020-06-22 20:13:36.208    3\n",
       "2020-06-08 17:17:26.335    3\n",
       "2020-06-08 16:50:44.596    3\n",
       "2020-06-15 19:24:26.737    3\n",
       "2020-06-08 19:49:21.686    3\n",
       "Name: start_time, dtype: int64"
      ]
     },
     "execution_count": 107,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dates_rounded_to_monday.value_counts().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 108,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    2020-06-01\n",
       "1    2020-06-01\n",
       "2    2020-06-01\n",
       "3    2020-06-01\n",
       "4    2020-06-01\n",
       "Name: start_time, dtype: object"
      ]
     },
     "execution_count": 108,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dates_rounded_to_monday.dt.date.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 109,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2020-06-15    481211\n",
       "2020-06-08    471384\n",
       "2020-06-22    465412\n",
       "2020-06-01    337590\n",
       "2020-06-29    126676\n",
       "Name: start_time, dtype: int64"
      ]
     },
     "execution_count": 109,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dates_rounded_to_monday.dt.date.value_counts()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 110,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>stop_time</th>\n",
       "      <th>duration</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2020-06-01 00:00:03.372</td>\n",
       "      <td>2020-06-01 00:17:46.208</td>\n",
       "      <td>0 days 00:17:42.836000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2020-06-01 00:00:03.553</td>\n",
       "      <td>2020-06-01 01:03:33.936</td>\n",
       "      <td>0 days 01:03:30.383000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2020-06-01 00:00:09.614</td>\n",
       "      <td>2020-06-01 00:17:06.833</td>\n",
       "      <td>0 days 00:16:57.219000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2020-06-01 00:00:12.178</td>\n",
       "      <td>2020-06-01 00:03:58.864</td>\n",
       "      <td>0 days 00:03:46.686000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2020-06-01 00:00:21.255</td>\n",
       "      <td>2020-06-01 00:24:18.965</td>\n",
       "      <td>0 days 00:23:57.710000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               start_time               stop_time               duration\n",
       "0 2020-06-01 00:00:03.372 2020-06-01 00:17:46.208 0 days 00:17:42.836000\n",
       "1 2020-06-01 00:00:03.553 2020-06-01 01:03:33.936 0 days 01:03:30.383000\n",
       "2 2020-06-01 00:00:09.614 2020-06-01 00:17:06.833 0 days 00:16:57.219000\n",
       "3 2020-06-01 00:00:12.178 2020-06-01 00:03:58.864 0 days 00:03:46.686000\n",
       "4 2020-06-01 00:00:21.255 2020-06-01 00:24:18.965 0 days 00:23:57.710000"
      ]
     },
     "execution_count": 110,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "citi_bike[\"duration\"] = (\n",
    "    citi_bike[\"stop_time\"] - citi_bike[\"start_time\"]\n",
    ")\n",
    "\n",
    "citi_bike.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 111,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Timedelta('0 days 00:27:19.590506853')"
      ]
     },
     "execution_count": 111,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "citi_bike[\"duration\"].mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 112,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "50593    32 days 15:01:54.940000\n",
       "98339    31 days 01:47:20.632000\n",
       "52306    30 days 19:32:20.696000\n",
       "15171    30 days 04:26:48.424000\n",
       "149761   28 days 09:24:50.696000\n",
       "Name: duration, dtype: timedelta64[ns]"
      ]
     },
     "execution_count": 112,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "citi_bike[\"duration\"].sort_values(ascending = False).head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 113,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>start_time</th>\n",
       "      <th>stop_time</th>\n",
       "      <th>duration</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>50593</th>\n",
       "      <td>2020-06-01 21:30:17.759</td>\n",
       "      <td>2020-07-04 12:32:12.699</td>\n",
       "      <td>32 days 15:01:54.940000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98339</th>\n",
       "      <td>2020-06-02 19:41:39.659</td>\n",
       "      <td>2020-07-03 21:29:00.291</td>\n",
       "      <td>31 days 01:47:20.632000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>52306</th>\n",
       "      <td>2020-06-01 22:17:10.908</td>\n",
       "      <td>2020-07-02 17:49:31.604</td>\n",
       "      <td>30 days 19:32:20.696000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15171</th>\n",
       "      <td>2020-06-01 13:01:41.942</td>\n",
       "      <td>2020-07-01 17:28:30.366</td>\n",
       "      <td>30 days 04:26:48.424000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>149761</th>\n",
       "      <td>2020-06-04 14:36:53.482</td>\n",
       "      <td>2020-07-03 00:01:44.178</td>\n",
       "      <td>28 days 09:24:50.696000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    start_time               stop_time                duration\n",
       "50593  2020-06-01 21:30:17.759 2020-07-04 12:32:12.699 32 days 15:01:54.940000\n",
       "98339  2020-06-02 19:41:39.659 2020-07-03 21:29:00.291 31 days 01:47:20.632000\n",
       "52306  2020-06-01 22:17:10.908 2020-07-02 17:49:31.604 30 days 19:32:20.696000\n",
       "15171  2020-06-01 13:01:41.942 2020-07-01 17:28:30.366 30 days 04:26:48.424000\n",
       "149761 2020-06-04 14:36:53.482 2020-07-03 00:01:44.178 28 days 09:24:50.696000"
      ]
     },
     "execution_count": 113,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "citi_bike.nlargest(n = 5, columns = \"duration\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 11.9 Summary"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
